home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / akcl / akcl1615.lha / mp / fplus.c next >
C/C++ Source or Header  |  1992-01-05  |  2KB  |  85 lines

  1. /* #include "include.h" */
  2. #include "config.h"
  3. /* #include "cmpinclude.h"   */
  4. /* #include "genpari.h" */
  5. #include "arith.h"
  6. object make_integer();  
  7.  
  8.  
  9. static unsigned long small_pos_int[3]={0x1000003,0x01000003,0};
  10. static unsigned long small_neg_int[3]={0x1000003,0xff000003,0};
  11. static unsigned long s4_neg_int[4]={0x1000004,0xff000004,1,0};
  12.  
  13. object
  14. fplus(a,b)
  15.      int a,b;
  16. { int z ;
  17.   int x;
  18.   if (a >= 0)
  19.    { if (b >= 0)
  20.        { x = a + b;
  21.      if (x == 0) return small_fixnum(0);
  22.      small_pos_int[2]=x;
  23.      return make_integer(small_pos_int);
  24.        }
  25.      else
  26.        { /* b neg */
  27.      x = a + b;
  28.      return make_fixnum(x);
  29.        }}
  30.   else
  31.     { /* a neg */
  32.       if (b >= 0)
  33.     { x = a + b;
  34.       return make_fixnum(x);}
  35.       else
  36.     { /* both neg */
  37.         { unsigned long Xtx,Xty,overflow,Xtres;
  38.           Xtres = addll(-a,-b);
  39.           if (overflow)
  40.         { 
  41.           s4_neg_int[3]=Xtres;
  42.           return make_integer(s4_neg_int);}
  43.           else
  44.         { small_neg_int[2]=Xtres;
  45.           return make_integer(small_neg_int);}
  46.         }}}
  47. }
  48.  
  49.  
  50. object
  51. fminus(a,b)
  52.      int a,b;
  53. { int z ;
  54.   int x;
  55.   if (a >= 0)
  56.    { if (b >= 0)
  57.        { x = a - b;
  58.      return make_fixnum(x);
  59.        }
  60.      else
  61.        { /* b neg */
  62.      x = a - b;
  63.      if (x==0) return small_fixnum(0);
  64.      small_pos_int[2]=x;
  65.      return make_integer(small_pos_int);
  66.        }}
  67.   else
  68.     { /* a neg */
  69.       if (b <= 0)
  70.     { x = a - b;
  71.       return make_fixnum(x);}
  72.       else
  73.     {  /* b positive */
  74.         { unsigned long Xtx,Xty,overflow,Xtres;
  75.           unsigned long t[4];
  76.           Xtres = addll(-a,b);
  77.           if (overflow)
  78.         { s4_neg_int[3]=Xtres;
  79.           return make_integer(s4_neg_int);}
  80.           else
  81.         { small_neg_int[2]=Xtres;
  82.           return make_integer(small_neg_int);}
  83.         }}}
  84. }
  85.